#include "MasterServer.hpp"
#include "EventHandlerUnknownConnection.hpp"
#include "cybertron/core/UtilTime.hpp"
#include "cybertron/core/Thread.hpp"
#include "TheApp.hpp"
#include "cybertron/core/UtilUrlRequest.hpp"
#pragma warning(disable:4996)
MasterServer::MasterServer()
{
	mListenPort = 0;
	UtilTime::millisecondsUpdate();
	zeroMembers();
}

MasterServer::~MasterServer()
{
	clearThis();
}
void MasterServer::SetListenPort(int ListenPort) {
	mListenPort = ListenPort;
}


void MasterServer::run()
{
	UtilTime::millisecondsUpdate();
	int t0 = UtilTime::millisecondsCurrent();

	for (;;)
	{
		UtilTime::millisecondsUpdate();
		int t1 = UtilTime::millisecondsCurrent();
		int ms = t1 - t0;
		t0 = t1;


		std::this_thread::sleep_for(std::chrono::milliseconds(200));
	}
}

void MasterServer::onAccept(SocketBasePtr pRemoteSocket)
{
	if (pRemoteSocket == nullptr)
	{
		return;
	}

	std::shared_ptr<EventHandlerUnknownConnection> pHandler = 
		std::make_shared<EventHandlerUnknownConnection>();
	pRemoteSocket->addHandler(pHandler);
}

void MasterServer::zeroMembers()
{
	//mGroupId = "Coordinator";
	//mType = std::to_string(TaskRunnerPool::ESONType::ECybertronCoordinator);;
	//mId = getId();
}

void MasterServer::clearThis()
{

	
}
